package com.hna.eking.AirlineServer.Mapper;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hna.eking.AirlineServer.Service.AirportInfoService;

public class SqlUtils {
	private Logger logger = LoggerFactory.getLogger(SqlUtils.class);
	public String MapinfoSelectListByInput(String airportCode, String mapCode, String mapType, int limit, int offset){
		String Sql = "select * from t_map_info where effect_flag = '0001' and map_Type <> 'AREA' ";
		if(airportCode != null && airportCode.length() != 0) {
			Sql += "and airport_code = #{0}";
		}
		if(mapCode != null  && mapCode.length() != 0) {
			Sql += "and map_name like '%'||#{1}||'%'";
		}
		if(mapType != null  && mapType.length() != 0) {
			Sql += "and map_type = #{2}";
		}
		Sql += " limit #{3} offset #{4} ";
		return Sql;
	}
	public String MapinfoSelectAreaByInput(String airportCode, String mapCode, int limit, int offset){
		String Sql = "select * from t_map_info where effect_flag = '0001' and map_Type = 'AREA' ";
		if(airportCode != null && airportCode.length() != 0) {
			Sql += "and airport_code = #{0}";
		}
		if(mapCode != null  && mapCode.length() != 0) {
			Sql += "and map_code = #{1} ";
		}
		 
		Sql += " limit #{2} offset #{3} ";
		return Sql;
	}
	public String MapinfoAreaCountByInput(String airportCode, String mapCode){
		String Sql = "select count(*) from t_map_info where effect_flag = '0001' and map_Type = 'AREA' ";
		if(airportCode != null && airportCode.length() != 0) {
			Sql += "and airport_code = #{0}";
		}
		if(mapCode != null  && mapCode.length() != 0) {
			Sql += "and map_code = #{1} ";
		}
		
		return Sql;
	}
	public String MapinfoSelectCountByInput(String airportCode, String mapCode, String mapType){
		String Sql = "select count(*) from t_map_info where effect_flag = '0001'  and map_Type <> 'AREA' ";
		if(airportCode != null  && airportCode.length() != 0) {
			Sql += "and airport_code = #{0}";
		}
		if(mapCode != null  && mapCode.length() != 0) {
			Sql += "and map_name like '%'||#{1}||'%'";
		}
		if(mapType != null  && mapType.length() != 0) {
			Sql += "and map_type = #{2}";
		}
		

		return Sql;
	}
	
	public String AirportSelectCountByInput(String airportcode, String province, String airportname) {
		String Sql = "select count(*) from t_airport_info where effect_flag = '0001' ";
		if(airportcode != null  && airportcode.length() != 0) {
			Sql += "and airport_code = #{0} ";
		}
		if(airportname != null  && airportname.length() != 0) {
			Sql += "and airport_Name like '%'||#{2}||'%'";
		}
		if(province != null  && province.length() != 0) {
			Sql += "and province = #{1}";
		}
		return Sql;
	}
	
	public String AirportSelectListByInput(String airportcode, String province, String airportname, int limit, int offset) {
		String Sql = "select * from t_airport_info where effect_flag = '0001' ";
		if(airportcode != null  && airportcode.length() != 0) {
			Sql += "and airport_code = #{0}";
		}
		if(airportname != null  && airportname.length() != 0) {
			Sql += "and airport_Name like '%'||#{2}||'%'";
		}
		if(province != null  && province.length() != 0) {
			Sql += "and province = #{1}";
		}
	
		Sql += " limit #{3} offset #{4} ";
		
		return Sql;
	}

	public String selectAllByAreaCode(String parentAreaCode) {
		String Sql = "select * from t_area_code where ";
		//logger.debug("乐乐测试" + parentAreaCode);
		if(parentAreaCode == null || parentAreaCode.length() == 0) {
			Sql += "parent_code is null";
		}else {
			Sql += "parent_code like #{0}||'%'";
		}
		
		return Sql;
	}
	
	public String AreaMapByInput(String mapCode, String mapName, int limit, int offset) {
		String Sql = "select * from T_Area_Info where effect_flag = '0001' ";
		if(mapCode != null  && mapCode.length() != 0) {
			Sql += "and map_code = #{0}";
		}
		if(mapName != null  && mapName.length() != 0) {
			Sql += "and map_name like '%'||#{1}||'%'";
		}
		
	
		Sql += " limit #{2} offset #{3} ";
		
		return Sql;
	}
	
	public String AreaMapCountByInput(String mapCode, String mapName) {
		String Sql = "select count(*) from T_Area_Info where effect_flag = '0001' ";
		if(mapCode != null  && mapCode.length() != 0) {
			Sql += "and map_code = #{0}";
		}
		if(mapName != null  && mapName.length() != 0) {
			Sql += "and map_name like '%'||#{1}||'%'";
		}
		
		return Sql;
	}
}
